package com.itheima.d0_homework.timu3.timu4;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();

        User u1 = new User("小明","123");
        User u2 = new User("小红","456");
        User u3 = new User("小勇","789");

        list.add(u1);
        list.add(u2);
        list.add(u3);

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("输入要注册的用户名");
            String id = scanner.next();
            System.out.println("输入要注册的密码");
            String passWorld = scanner.next();

            for (int i = 0; i < list.size(); i++) {
                String user = list.get(i).getUserId();
                String user1 = list.get(i).getPassWord();
              if((id.equals(user))){
                  System.out.println("用户名已存在");
                  break;
              }else if(passWorld.equals(user1)){
                  System.out.println("密码已存在");
                  break;
              }else {
                  User user2 = new User(id, passWorld);
                  list.add(user2);

                  for (User newUser : list) {
                      System.out.println(newUser);
                  }
                  break;
              }

            }

        }
    }
}
